package easy;

import util.PrintUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Solution_884 {

    public String[] uncommonFromSentences(String s1, String s2) {
        String[] split1 = s1.split(" ");
        String[] split2 = s2.split(" ");
        Map<String, Integer> map = new HashMap<>();
        for (String s : split1) {
            Integer count = map.getOrDefault(s, 0);
            map.put(s, ++count);
        }
        List<String> list = new ArrayList<>();

        for (String s : split2) {
            Integer count = map.getOrDefault(s, 0);
            map.put(s, ++count);
        }
        for (String key : map.keySet()) {
            if (map.get(key) == 1) {
                list.add(key);
            }
        }
        return list.toArray(new String[0]);
    }

    public static void main(String[] args) {
        Solution_884 model = new Solution_884();
        PrintUtils.array(model.uncommonFromSentences("this apple is sweet", "this apple is sour"));
        PrintUtils.array(model.uncommonFromSentences("apple apple", "banana"));

    }
}
